import { msg } from '../../components/notice/notice';
import { Friends, isFriend } from '/imports/models/Friends';

Template.exploreUserCard.helpers({
  isCurrent: function() {
    let current = Meteor.userId();
    if (current == Template.instance().data.user._id) {
      return true;
    }
  },
  isFriend: function() {
    return isFriend(Meteor.userId(), Template.instance().data.user._id);
  },
  getEmail: function() {
    return Template.instance().data.user.emails[0].address;
  }
});

Template.exploreUserCard.events({
  'click .explore-user-make-friend'(event, instance) {
    event.preventDefault();
    let friend_id = instance.data.user._id;
    
    Meteor.call('makeFriend', friend_id, (error, result) => {
      if (result) {
        msg({content: '加好友请求已发送成功'});
        $('.explore-user-make-friend').attr('disabled', true);
      }
    });
  }
});
